<template>
  <a-layout-header style="background: #fff; padding: 0">
    <a-icon class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="colla" />
    <div class="crumb">
      <a-breadcrumb>
        <a-breadcrumb-item v-for="(urlName, index) in routeName" :key="index">{{ urlName }}</a-breadcrumb-item>
      </a-breadcrumb>
    </div>
    <div class="drop">
      <a-dropdown>
        <span class="action ant-dropdown-link user-dropdown-menu">
          <a-avatar class="avatar" icon="user" />
          <span>{{ userInfo.user.username || null }}</span>
          <!-- <a-avatar class="avatar" size="small" :src="avatar"/> -->
          <!-- <span>{{ nickname }}</span> -->
        </span>
        <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
          <a-menu-item key="0" @click="toHome">
            <!-- <router-link to="/center"> -->
              <a-icon type="home" />
              <span>首页</span>
            <!-- </router-link> -->
          </a-menu-item>
          <a-menu-item v-if="userInfo.merchantRespParams" key="1" @click="toCenter">
            <!-- <router-link to="/center"> -->
              <a-icon type="user" />
              <span>商户信息</span>
            <!-- </router-link> -->
          </a-menu-item>
          <a-menu-item key="2" @click="toSetting">
            <!-- <router-link to="/setting"> -->
              <a-icon type="setting" />
              <span>账户设置</span>
            <!-- </router-link> -->
          </a-menu-item>
          <!-- <a-menu-item key="3" @click="toTesting">
              <a-icon type="alipay" />
              <span>支付测试</span>
          </a-menu-item> -->
          <a-menu-divider />
          <a-menu-item key="4">
            <a href="javascript:;" @click="loginOut">
              <a-icon type="logout" />
              <span>退出登录</span>
            </a>
          </a-menu-item>
        </a-menu>
      </a-dropdown>
    </div>
  </a-layout-header>
</template>

<script>
import { mapState } from "vuex";
import * as API from "../api/login";
import { loginOut } from "../utils/expries";
import { demo } from "../utils/env-setup";
export default {
  props: {
    collapsed: {
      type: Boolean,
      detail: false
    }
  },
  computed: {
    ...mapState({
      routeName: state => state.router.routeName,
      userInfo: state => state.user.userInfo
    })
  },
  methods: {
    loginOut,
    colla() {
      this.$emit("colla");
    },
    loginOutAction() {
      API.logoutApi().then(res => {
        if (res.code == 200) {
          this.loginOut()
        }
      });
    },
    toHome (){
      this.$router.push({
        path: "/home"
      })
    },
    toCenter (){
      this.$router.push({
        path: "/center"
      })
    },
    toSetting (){
      this.$router.push({
        path: "/setting"
      })
    },
    // toTesting (){
    //   window.open(demo,"_blank"); 
    // }
  }
};
</script>
<style lang="less" scoped>
.trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}
.crumb {
  // float: left;
  display: inline-block;
  // margin-left: 30px;
  .ant-breadcrumb {
    span {
      line-height: 80px;
    }
  }
}

.trigger:hover {
  color: #1890ff;
}
.drop {
  float: right;
  margin-right: 30px;
  line-height: 1.5;
  cursor: pointer;
  padding: 0 12px;
  // display: inline-block;
  -webkit-transition: all 0.3s;
  transition: all 0.3s;
  height: 100%;
  color: rgba(0, 0, 0, 0.65);
  // a {
  // color: #606266;
  // }
}
.avatar {
  margin: 20px 8px 20px 0;
  color: #1890ff;
  background: hsla(0, 0%, 100%, 0.85);
  vertical-align: middle;
}
.user-dropdown-menu{
  font-family: 'SunXiaoSongXiaFenTi';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.user-dropdown-menu-wrapper {
  margin-top: 18px;
}
</style>